﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using HomeStayWebCP.Models.BusinessObject;
using HomeStayWebCP.Utility;

namespace HomeStayWebCP.Models
{
    public class NewModel
    {
        NewsDataModel nmodel = new NewsDataModel();
        public List<NewsItem> GetAllNew()
        {
            List<NewsItem> result = new List<NewsItem>();
            List<Store_New_GetAllNews_Result> list = nmodel.GetNews();
            foreach (var item in list)
            {
                NewsItem i = new NewsItem();
                i.ID = item.NewID;
                i.title = item.Title;
                i.pubDate = item.TimeCreated.ToShortDateString();
                i.image = Util.imageNew + item.ImageURL;
                i.header = item.Header;
                result.Add(i);
            }
            return result;
        }
        public void AddNew(NewObject obj,string createdby)
        {           
            News news = new News();
            news.Title = obj.Title;
            news.Content = obj.Content;
            news.Header = obj.Header;
            news.ImageURL = obj.Image;
            news.IsDeleted = false;
            news.TimeCreated = DateTime.Now;
            news.CreatedBy = createdby;
            nmodel.AddNew(news);
            //return result;                    
        }
        public News GetNewDetails(int newID)
        {
            News news = nmodel.GetNewDetail(newID);
            return news;
        }
        public bool DeleteNew(int newID)
        {
            if (nmodel.DeleteNew(newID) > 0)
            {
                return true;
            }
            return false;
        }
    }
}